home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / Networking / TCP Server / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  1.6 KB  |  86 lines  |  [TEXT/KAHL]

  1. /*
  2.     TCP Client/Server Queuing Example
  3.     Steve Falkenburg, MacDTS, Apple Computer
  4.     3/11/92
  5.     
  6.     this client/server sample uses MacTCP to implement a simple "greeting" server.  the server
  7.     opens up several listeners on kGreetingPort (1235).  when a client connects, the data entered
  8.     in the greeting dialog is sent to the remote connection, and the connection is closed.
  9.     
  10.     connection management is done through the use of Operating System queues to simplify tracking
  11.     and usage.
  12. */
  13.  
  14.  
  15. #include "const.h"
  16. #include "globals.h"
  17. #include "utils.h"
  18. #include "queues.h"
  19. #include "network.h"
  20. #include "events.h"
  21. #include "interface.h"
  22. #include "main.h"
  23.  
  24.  
  25. /* main entry point */
  26.  
  27. void main(void)
  28. {
  29.     InitMac();
  30.     InitQueues();
  31.     InitInterface();
  32.  
  33.     if (InitNetwork()!=noErr)
  34.         ExitToShell();
  35.         
  36.     MainLoop();
  37.     
  38.     CloseNetwork();
  39.     ExitToShell();
  40. }
  41.  
  42.  
  43. /*    initialize macintosh managers and some globals */
  44.  
  45. void InitMac(void)
  46. {
  47.     SysEnvRec envRec;
  48.     
  49.     InitGraf(&qd.thePort);
  50.     InitFonts();
  51.     InitWindows();
  52.     InitMenus();
  53.     TEInit();
  54.     InitDialogs(nil);
  55.     InitCursor();
  56.     FlushEvents(everyEvent,0);
  57.     
  58.     if (SysEnvirons(1,&envRec)!=noErr)
  59.         gRunningSeven = false;
  60.     else
  61.         gRunningSeven = (envRec.systemVersion >= 0x700);
  62.     
  63.     if (gRunningSeven)
  64.         GetCurrentProcess(&gOurPSN);
  65. }
  66.  
  67.  
  68. /*    main event loop.  note that we use a *very* large sleeptime if we're running under System 7
  69. */
  70.  
  71. #define    GetSleepTime    (gRunningSeven ? 100:100000)
  72.  
  73. void MainLoop(void)
  74. {
  75.     EventRecord ev;
  76.     
  77.     while (!gDone) {
  78.         if (WaitNextEvent(everyEvent,&ev,GetSleepTime,nil)) {
  79.             HandleEvent(&ev);
  80.         }
  81.         else HandleIdleTime(&ev);
  82.         UpdateNumberList();
  83.     }
  84. }
  85.  
  86.